const backTop = document.querySelector(".backtop")
document.onscroll = function () {
    let scrollT = document.documentElement.scrollTop;
    if (scrollT >= 380) {
        backTop.style.display = "block";
    } else {
        backTop.style.display = "none";

    }
}
backTop.onclick = function () {
    let p = document.documentElement.scrollTop;
    clearInterval(t);
    
    // console.log(p)
    var t = setInterval(() =>{
        
        // let st = document.documentElement.scrollTop;
        // console.log(st)
        let speed = document.documentElement.scrollTop / 8;
        speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);

        if(p !== document.documentElement.scrollTop){
            clearInterval(t);
        }
        document.documentElement.scrollTop -= speed;
        p = document.documentElement.scrollTop;
        // console.log(p)
        // if(p !== document.documentElement.scrollTop){
        //     clearInterval(t);
        // }
        if (document.documentElement.scrollTop === 0) {
            clearInterval(t)
        }
    }, 15)
}